package com.kogi.androidpatt.gettingInput.enterText;

import com.kogi.patterns.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class panAndScan extends Activity  implements OnEditorActionListener
{
	private EditText color1,color2,color3; 
	private TextView colorBox1,colorBox2,colorBox3,colorBox;
	@Override
	 protected void onCreate(Bundle savedInstanceState) 
	 {		
		super.onCreate(savedInstanceState);
	    setContentView(R.layout.getting_input_panandscan);
	    color1 = (EditText)findViewById(R.id.nameColor1);
	    color1.setOnEditorActionListener(this);
	    colorBox1 = (TextView)findViewById(R.id.color1);
	    color2 = (EditText)findViewById(R.id.nameColor2);
	    color2.setOnEditorActionListener(this);
	    colorBox2 = (TextView)findViewById(R.id.color2);
	    color3 = (EditText)findViewById(R.id.nameColor3);
	    color3.setOnEditorActionListener(this);
	    colorBox3 = (TextView)findViewById(R.id.color3);
//	    colorBox = (TextView)findViewById(R.id.colorBox);
	 }
	
	@Override
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
	{
		if(actionId == 0)//input done
		{	
			InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.hideSoftInputFromWindow(v.getWindowToken(), 0);//close keyboard
			try
			{
				if (v == this.color1)
					colorBox1.setBackgroundColor(Color.parseColor(color1.getText().toString().trim()));
				if (v == this.color2)
					colorBox2.setBackgroundColor(Color.parseColor(color2.getText().toString().trim()));
				if (v == this.color3)
					colorBox3.setBackgroundColor(Color.parseColor(color3.getText().toString().trim()));
				//colorBox.setBackgroundColor(c);
				return true;
				
			}
			catch(Exception e)
			{
				return false;
				//continue with the running app
			}
		}
		else
			return false;
    }
}
